package com.synnex.mobile.servier.core.content.bo;

import com.synnex.mobile.generic.core.util.ObjectUtil;
import com.synnex.mobile.servier.core.content.dto.Content;
import com.synnex.mobile.servier.core.content.dto.Groups;
import com.synnex.mobile.servier.core.msgBoard.dto.MsgDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kerryf
 * To change this template use File | Settings | File Templates.
 */
public class ContentBo extends Content {

    private String groupName;
    private Integer groupId;

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public Integer getGroupId() {
        return groupId;
    }

    public void setGroupId(Integer groupId) {
        this.groupId = groupId;
    }

    public static ContentBo createInstance(Content content){

        if(content!=null){
            return ObjectUtil.copyProperties(content,ContentBo.class);
        }else{
            return null;
        }
    }

    public static ContentBo createInstance(Content content,List<Groups> groupsList){

        if(content!=null){
            ContentBo contentBo = ObjectUtil.copyProperties(content,ContentBo.class);
            if(contentBo.getGroup()!=null){
                for(Groups groups: groupsList){
                    if(content.getGroup().intValue() == groups.getId().intValue()){
                        contentBo.setGroupName(groups.getGroupName());
                        contentBo.setGroupId(groups.getId());
                        contentBo.setSeq(groups.getSeq());
                    }
                }
            }
            return contentBo;
        }else{
            return null;
        }
    }

    public static List<ContentBo> createInstance(List<Content> contents){

        List<ContentBo> contentBos = new ArrayList<ContentBo>();
        if (contents != null) {
            for (Content content : contents) {
                contentBos.add(createInstance(content));
            }
        }
        return contentBos;
    }

    public static List<ContentBo> createInstance(List<Content> contents,List<Groups> groups){

        List<ContentBo> contentBos = new ArrayList<ContentBo>();
        if (contents != null) {
            for (Content content : contents) {
                contentBos.add(createInstance(content,groups));
            }
        }
        return contentBos;
    }

}
